package com.bs.utils;

import java.util.HashMap;
import java.util.Map;

public class Result {

	private int code;
	private Map<String, Object> data=new HashMap<String, Object>();
	private String msg;
	
	public Result(int code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}
//	数据存储
	public Result put(String key,Object value) {
		this.data.put(key, value);
		return this;
	}
	public Result remove(String key) {
		this.data.remove(key);
		return this;
	}
//	创建Result对象
	public static Result get(Integer code,String msg) {
		return new Result(code,msg);
	}
//	成功
	public static Result success() {
		return get(200, "请求成功");
	}
	public static Result success(String msg) {
		return get(200, msg);
	}
//	失败
	public static Result fail(int code,String msg) {
		return get(code, msg);
	}
	public static Result fail(int code) {
		return get(code, "请求失败");
	}
	public static Result fail(String msg) {
		return get(0, msg);
	}
	public static Result fail() {
		return get(0, "请求失败");
	}
//	getter、setter
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public Map<String, Object> getData() {
		return data;
	}
	public void setData(Map<String, Object> data) {
		this.data = data;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	@Override
	public String toString() {
		return "Result [code=" + code + ", data=" + data + ", msg=" + msg + "]";
	}
}
